/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * TabelaPadraoForm.java
 *
 * Created on 27/07/2011, 10:25:26
 */

package savet.gui.tabelas;

import savet.gui.controllers.TabelaPadraoController;
import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.openswing.swing.form.client.Form;
import savet.entidades.Trabalhador;
import savet.util.Trabalhadores;

/**
 *
 * @author Adisson
 */
public class TabelaPadraoForm extends Form {

    private TabelaPadraoController controller;
    /** Creates new form TabelaPadraoForm */
    public TabelaPadraoForm(TabelaPadraoController controller) {
        this.controller = controller;
        initComponents();
        tabelaPadrao.setController(controller);
        tabelaPadrao.setGridDataLocator(controller);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        tabelaPadrao = new org.openswing.swing.client.GridControl();
        textColumn1 = new org.openswing.swing.table.columns.client.TextColumn();
        textColumn2 = new org.openswing.swing.table.columns.client.TextColumn();
        dateColumn1 = new org.openswing.swing.table.columns.client.DateColumn();
        dateColumn2 = new org.openswing.swing.table.columns.client.DateColumn();
        textColumn3 = new org.openswing.swing.table.columns.client.TextColumn();
        checkBoxColumn1 = new org.openswing.swing.table.columns.client.CheckBoxColumn();
        textColumn4 = new org.openswing.swing.table.columns.client.TextColumn();
        navigatorBar = new org.openswing.swing.client.NavigatorBar();
        reloadButton = new org.openswing.swing.client.ReloadButton();
        editButton = new org.openswing.swing.client.EditButton();
        insertButton = new org.openswing.swing.client.InsertButton();
        deleteButton = new org.openswing.swing.client.DeleteButton();
        importButton = new org.openswing.swing.client.ImportButton();
        saveButton = new org.openswing.swing.client.SaveButton();

        FormListener formListener = new FormListener();

        setVOClassName("savet.entidades.Trabalhador");

        tabelaPadrao.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        tabelaPadrao.setDeleteButton(deleteButton);
        tabelaPadrao.setFunctionId("carregaTrabalhadores");
        tabelaPadrao.setInsertButton(insertButton);
        tabelaPadrao.setInsertRowsOnTop(false);
        tabelaPadrao.setMode(javax.swing.ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
        tabelaPadrao.setNavBar(navigatorBar);
        tabelaPadrao.setOrderWithLoadData(false);
        tabelaPadrao.setReloadButton(reloadButton);
        tabelaPadrao.setSaveButton(saveButton);
        tabelaPadrao.setShowFilterPanelOnGrid(true);
        tabelaPadrao.setValueObjectClassName("savet.entidades.Trabalhador");
        tabelaPadrao.getColumnContainer().setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEFT));

        textColumn1.setAdditionalHeaderColumnName("Texto");
        textColumn1.setAdditionalHeaderColumnSpan(2);
        textColumn1.setColumnFilterable(true);
        textColumn1.setColumnName("nome");
        textColumn1.setEditableOnEdit(true);
        textColumn1.setEditableOnInsert(true);
        textColumn1.setPreferredWidth(350);
        textColumn1.setSortVersus(org.openswing.swing.util.java.Consts.ASC_SORTED);
        tabelaPadrao.getColumnContainer().add(textColumn1);

        textColumn2.setColumnName("pis");
        textColumn2.setEditableOnEdit(true);
        textColumn2.setEditableOnInsert(true);
        textColumn2.setPreferredWidth(110);
        textColumn2.setSortVersus(org.openswing.swing.util.java.Consts.ASC_SORTED);
        tabelaPadrao.getColumnContainer().add(textColumn2);

        dateColumn1.setColumnName("admissao");
        dateColumn1.setEditableOnEdit(true);
        dateColumn1.setEditableOnInsert(true);
        dateColumn1.setPreferredWidth(110);
        dateColumn1.setSortVersus(org.openswing.swing.util.java.Consts.ASC_SORTED);
        tabelaPadrao.getColumnContainer().add(dateColumn1);

        dateColumn2.setColumnName("afastamento");
        dateColumn2.setColumnRequired(false);
        dateColumn2.setEditableOnEdit(true);
        dateColumn2.setEditableOnInsert(true);
        dateColumn2.setPreferredWidth(110);
        dateColumn2.setSortVersus(org.openswing.swing.util.java.Consts.ASC_SORTED);
        tabelaPadrao.getColumnContainer().add(dateColumn2);

        textColumn3.setColumnName("codAfastamento");
        textColumn3.setColumnRequired(false);
        textColumn3.setEditableOnEdit(true);
        textColumn3.setEditableOnInsert(true);
        textColumn3.setPreferredWidth(110);
        textColumn3.setSortVersus(org.openswing.swing.util.java.Consts.ASC_SORTED);
        tabelaPadrao.getColumnContainer().add(textColumn3);

        checkBoxColumn1.setColumnName("aprendiz");
        checkBoxColumn1.setEditableOnEdit(true);
        checkBoxColumn1.setEditableOnInsert(true);
        checkBoxColumn1.setPreferredWidth(50);
        checkBoxColumn1.setSortVersus(org.openswing.swing.util.java.Consts.ASC_SORTED);
        tabelaPadrao.getColumnContainer().add(checkBoxColumn1);

        textColumn4.setColumnName("genero");
        textColumn4.setColumnSortable(true);
        textColumn4.setEditableOnEdit(true);
        textColumn4.setEditableOnInsert(true);
        textColumn4.setPreferredWidth(50);
        textColumn4.setSortVersus(org.openswing.swing.util.java.Consts.ASC_SORTED);
        tabelaPadrao.getColumnContainer().add(textColumn4);

        deleteButton.addActionListener(formListener);

        importButton.setAttributeName("codAfastamento");
        importButton.addActionListener(formListener);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(tabelaPadrao, javax.swing.GroupLayout.DEFAULT_SIZE, 1213, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(navigatorBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(reloadButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(insertButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(editButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(saveButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(deleteButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(importButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(tabelaPadrao, javax.swing.GroupLayout.DEFAULT_SIZE, 456, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(navigatorBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(reloadButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(insertButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(editButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(deleteButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(importButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(saveButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );
    }

    // Code for dispatching events from components to event handlers.

    private class FormListener implements java.awt.event.ActionListener {
        FormListener() {}
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            if (evt.getSource() == deleteButton) {
                TabelaPadraoForm.this.deleteButtonActionPerformed(evt);
            }
            else if (evt.getSource() == importButton) {
                TabelaPadraoForm.this.importButtonActionPerformed(evt);
            }
        }
    }// </editor-fold>//GEN-END:initComponents

    private void importButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_importButtonActionPerformed
        File arquivo = Trabalhadores.getArquivoDeFileChooser(this);
        try {
            List<Trabalhador> listaTrabalhadores = Trabalhadores.getTrabalhadoresSimples(arquivo);
            controller.setListaTrabalhadores(listaTrabalhadores);
            tabelaPadrao.reloadData();
        } catch (IOException ex) {
            Logger.getLogger(TabelaPadraoForm.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_importButtonActionPerformed

    private void deleteButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_deleteButtonActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_deleteButtonActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private org.openswing.swing.table.columns.client.CheckBoxColumn checkBoxColumn1;
    private org.openswing.swing.table.columns.client.DateColumn dateColumn1;
    private org.openswing.swing.table.columns.client.DateColumn dateColumn2;
    private org.openswing.swing.client.DeleteButton deleteButton;
    private org.openswing.swing.client.EditButton editButton;
    private org.openswing.swing.client.ImportButton importButton;
    private org.openswing.swing.client.InsertButton insertButton;
    private org.openswing.swing.client.NavigatorBar navigatorBar;
    private org.openswing.swing.client.ReloadButton reloadButton;
    private org.openswing.swing.client.SaveButton saveButton;
    private org.openswing.swing.client.GridControl tabelaPadrao;
    private org.openswing.swing.table.columns.client.TextColumn textColumn1;
    private org.openswing.swing.table.columns.client.TextColumn textColumn2;
    private org.openswing.swing.table.columns.client.TextColumn textColumn3;
    private org.openswing.swing.table.columns.client.TextColumn textColumn4;
    // End of variables declaration//GEN-END:variables

}
